<template>
  <div>
    <div class="top">
      <span
        @click="$emit('ishow')"
        style="float: left; padding-left: 10px"
        class="toutiao toutiao-zuojiantou"
      ></span>
      <span>{{ results.length > 0 ? results.length+'条回复' : '暂无回复' }}</span>
    </div>
    <!-- 评论 -->
    <div class="pin">
      <div class="kuai">
        <van-cell :title="myId.aut_name" :label="myId.content">
          <template #icon
            ><van-image
              round
              width="0.9rem"
              height="0.9rem"
              :src="myId.aut_photo"
          /></template>
          <span class="toutiao bottom toutiao-dianzan2" style="float: right"
            >赞</span
          >
        </van-cell>
        <div class="color">
          <div style="display: inline-block">
            {{ pubdateB(myId.pubdate) }}&nbsp;&nbsp;&nbsp;
          </div>
          <div class="div" style="display: inline-block; margin-top: -3px">
            <van-button type="default"
              ><span>回复</span><span>{{ myId.reply_count }}</span></van-button
            >
          </div>
        </div>
      </div>
    </div>
    <!-- 回复的评论 -->
    <div class="mY">
      <van-divider />
      <div class="navtop">全部回复</div>
      <van-divider />
      <div class="pin" v-if="results.length > 0">
        <div class="kuai" v-for="(itme, index) in results" :key="index">
          <van-cell :title="itme.aut_name" :label="itme.content">
            <template #icon
              ><van-image
                round
                width="0.9rem"
                height="0.9rem"
                :src="itme.aut_photo"
            /></template>
            <span class="toutiao bottom toutiao-dianzan2" style="float: right"
              >赞</span
            >
          </van-cell>
          <div class="color">
            <div style="display: inline-block">
              {{ pubdateB(itme.pubdate) }}&nbsp;&nbsp;&nbsp;
            </div>
            <div class="div" style="display: inline-block; margin-top: -3px">
              <van-button type="default"
                ><span>回复</span
                ><span>{{ itme.reply_count }}</span></van-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="foor">
      <van-button type="default" @click="isshowComment = true">评论</van-button>
    </div>
    <!-- 底部弹出 -->
    <div class="footer">
      <van-popup
        v-model="isshowComment"
        position="bottom"
        :style="{ height: '30%' }"
      >
        <div class="divleft">
          <van-field
            v-model.trim="message"
            rows="2"
            :autosize="auto"
            type="textarea"
            maxlength="50"
            placeholder="请输入留言"
            show-word-limit
          />
        </div>
        <div class="divright" @click="isconten">发布</div>
      </van-popup>
    </div>
  </div>
</template>

<script>
import dayjs from '@/utils/day'
import { GetCommentsAppi, pinCommentsApi } from '@/api'
export default {
  watch: {
    isshowComment() {
      this.message = ''
    }
  },
  data() {
    return {
      isshowComment: false,
      auto: { maxHeight: 100, minHeight: 80 },
      message: '',
      results: []
    }
  },
  name: 'ID',
  props: ['wzId', 'myId'],
  async created() {
    const {
      data: { data }
    } = await GetCommentsAppi('c', this.myId.com_id)
    this.results = data.results
  },
  methods: {
    pubdateB(c) {
      const a = dayjs(new Date())
      return dayjs(c).from(a)
    },
    //发起评论
    async isconten() {
      try {
        this.$toast.loading({
          message: '加载中...',
          forbidClick: true
        })
        const { wzId, myId, message } = this
        await pinCommentsApi(myId.com_id, message, wzId)
        const {
          data: { data }
        } = await GetCommentsAppi('c', myId.com_id)
        this.results = data.results
        this.isshowComment = false
        this.$toast.success('评论成功')
      } catch (error) {}
    }
  }
}
</script>

<style scoped lang="less">
.top {
  height: 100px;
  border-bottom: 1px solid #ccc;
  text-align: center;
  line-height: 100px;
  font-size: 40px;
}
:deep(.pin) {
  margin-bottom: 100px;
  .van-image {
    margin-top: 10px;
    margin-right: 7px;
  }
  .span {
    font-size: 30px;
  }
  .color {
    margin-left: 104px;
    font-size: 24px;
    height: 40px;
    line-height: 40px;
    display: flex;
    align-items: center;
  }
  .van-button {
    width: 100%;
    height: 100%;
    width: 125px;
    height: 40px;
    font-size: 12px;
    text-align: center;
    border-radius: 40px;
  }
  .van-button--normal {
    padding: unset;
  }
  .van-cell::after {
    border-bottom: unset;
  }
}
:deep(.mY) {
  .navtop {
    font-size: 28px;
    color: #111;
  }
  :deep(.pin) {
    .van-image {
      margin-top: 10px;
      margin-right: 7px;
    }
    .span {
      font-size: 30px;
    }
    .color {
      margin-left: 104px;
      font-size: 24px;
      height: 40px;
      line-height: 40px;
      display: flex;
      align-items: center;
    }
    .van-button {
      width: 100%;
      height: 100%;
      width: 125px;
      height: 40px;
      font-size: 12px;
      text-align: center;
      border-radius: 40px;
    }
    .van-button--normal {
      padding: unset;
    }
    .van-cell::after {
      border-bottom: unset;
    }
  }
}
:deep(.footer) {
  .divleft {
    display: inline-block;
    width: 80%;
    margin: 50px 0 0 34px;
    overflow: hidden;
  }
  .van-cell {
    border: 1px solid #ccc;
    background-color: #f5f7f9;
    border-radius: 20px;
  }
  .divright {
    display: inline-block;
    font-size: 30px;
    color: #b5d1ec;
    margin-left: 25px;
    position: relative;
    top: -100px;
  }
}
:deep(.foor) {
  width: 100%;
  position: fixed;
  bottom: 0;
  height: 100px;
  background-color: pink;
  text-align: center;

  .van-button {
    width: 80%;
    border-radius: 60px;
    margin-top: 5px;
  }
}
</style>
